package log

import (
	"time"
	"yybk/model"
)

func SaveLog(teacherId string, courseId string, reason string) error {
	var teacher model.Teacher
	if err := model.DB.Where("id = ?", teacherId).First(&teacher).Error; err != nil {
		return err
	}

	log := model.Log{
		TeacherId:   teacherId,
		TeacherName: teacher.Name,
		Institute:   teacher.Institute,
		Reason:      reason,
		CreateTime:  time.Now(),
		CourseId:    courseId,
	}

	if err := model.DB.Create(&log).Error; err != nil {
		return err
	}

	return nil
}
